//
//  CYStatusToolBar.swift
//  WeiBo
//
//  Created by Mr_J on 16/3/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class CYStatusToolBar: UIView {
    
 
    
    private var retweetButton: UIButton!
    private var unlikeButton: UIButton!
    private var commentButton: UIButton!
    
    var statusViewModel: CYStatusViewModel? {
        didSet{
            
            retweetButton.setTitle(statusViewModel?.repostsCountStr, forState: UIControlState.Normal)
            commentButton.setTitle(statusViewModel?.commentsCountStr, forState: UIControlState.Normal)
            unlikeButton.setTitle(statusViewModel?.attitudesCountStr, forState: UIControlState.Normal)
            
        }
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
         retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
         commentButton = addChildButton("timeline_icon_comment", title: "评论")
         unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
        
        commentButton.addTarget(self, action: "ZZ", forControlEvents: UIControlEvents.TouchUpInside)
        
        let sp1 = addSpliteView()
        let sp2 = addSpliteView()
        
        
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.leading.top.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.bottom.equalTo(retweetButton)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentButton.snp_trailing)
            make.top.bottom.equalTo(commentButton)
            make.trailing.equalTo(self)
        }
        
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)
            
        }
        
    }
    
    //添加分割线
    private func addSpliteView()->UIView {
        let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(imageView)
        return imageView
    }
    
    
    private func addChildButton(imageNamed:String, title: String) ->UIButton {
        
        
        let button = UIButton()
        
        button.setTitle(title, forState: UIControlState.Normal)
        button.setImage(UIImage(named:imageNamed), forState: UIControlState.Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        addSubview(button)
        
        return button
    }
    
    @objc private func ZZ() {
        
        let vc = CYNavigationController(rootViewController: CYpinglunNaviCotroller())
        
        NSNotificationCenter.defaultCenter().postNotificationName("CryZz", object: vc)
         print("aaaa")

        
    }
    
    
}
